package com.sxj.corejava.code08_常用类.泛型;

/**
 * @author 石小俊
 * 2024年07月23日 13:31
 */
public class Test01_泛型类 {
    public static void main(String[] args) {
        Student student = new Student();
        // 如果参数类型是一个Object,此时可以表示任意类型
        // 但是该方式内部是做了自动类型转换
        // 这种方式类型不安全,不建议使用
        student.setNo("jsj001");
        student.setName("admin");

        Student student2 = new Student();
        student2.setNo(1);
        student2.setName("alice");

        User<Integer> user = new User<Integer>();
        user.setId(1);
        User<String> user2 = new User<>();
        user2.setId("1");
    }
}

class Student {
    private Object no;
    private String name;

    public Object getNo() {
        return no;
    }

    public void setNo(Object no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class User<T> {
    private T id;
    private String name;

    public User(T id, String name) {
        this.id = id;
        this.name = name;
    }

    public User() {
    }

    public T getId() {
        return id;
    }

    public void setId(T id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
